// 省份的自定义覆盖物
var opts = {
    width: 80,     // 信息窗口宽度
    height: 70,     // 信息窗口高度
};

function getEnergy() {
    return 1;
}
function AreaOverlay(point, porperation, position) {
    this._point = point;
    this._porperation = porperation;
    this._position = position;
}
Number.prototype.toPercent = function () {
    var result = (Math.round(this * 10000) / 100).toFixed(2);
    if (result > 100) {
        result = 100;
    }
    return result + '%';
};
function bbb() {
    var selectType = $('#selectType').val();
    return selectType;
}
function addListener(map, div, position, point) {
    var infoWindow;
    var power = [];
    div.addEventListener("mouseover", function () {
        power[0] = parseInt($("#all-energy").text());
        power[1] = parseInt($("#center-energy").text());
        power[2] = parseInt($("#right-energy").text());
        var searchDate = bbb();
        var val = "<div align='center' id='messageWindow'>" + position + "</div>";
        var param = {
            "position": position,
            "searchDate": searchDate
        };
        $.ajax({
            contentType: "application/json",
            url: "getEnergyArea.shtml",
            data: param,
            async: false,
            dataType: "json",
            success: function (data) {
                $.each(data, function (item, element) {
                    var percent = element.power / power[item];
                    val = val + element.name + "耗能：" + element.power + "度(" + percent.toPercent() + ")<br/>";
                })
            }
        });
        infoWindow = new BMap.InfoWindow(val, opts);
        infoWindow.enableCloseOnClick();
        map.openInfoWindow(infoWindow, point);
    });
}
AreaOverlay.prototype = new BMap.Overlay();
AreaOverlay.prototype.initialize = function (map) { //省覆盖原型初始化
    var point = this._point;
    var porperation = this._porperation;
    var position = this._position;
    this._map = map;
    var div = this._div = document.createElement("div");
    addListener(map, div, position, point);
    div.className = "area-overlay";
    var len = 18;
    //var len = 24*porperation > 10 ? 24*porperation : 10;
    div.style.width = len + 'px';
    div.style.height = len + 'px';
    var img = document.createElement("img");
    img.src = URL_PATH + '/src/map/position.gif';
    div.appendChild(img);
    map.getPanes().labelPane.appendChild(div);
    map.getPanes().labelPane.appendChild(div);
    return div;
};
AreaOverlay.prototype.draw = function () {
    var map = this._map;
    var pixel = map.pointToOverlayPixel(this._point);
    this._div.style.left = pixel.x + "px";
    this._div.style.top = pixel.y - 5 + "px";
};

// 城市的自定义覆盖物
function CityOverlay(point) {
    this._point = point;
}
CityOverlay.prototype = new BMap.Overlay();
CityOverlay.prototype.initialize = function (map) { //省覆盖原型初始化
    var point = this._point;
    this._map = map;
    var div = this._div = document.createElement("div");
    div.className = "city-overlay";
    div.style.width = 8 + 'px';
    div.style.height = 8 + 'px';
    map.getPanes().labelPane.appendChild(div);
    return div;
};
CityOverlay.prototype.draw = function () {
    var map = this._map;
    var pixel = map.pointToOverlayPixel(this._point);
    this._div.style.left = pixel.x - 4 + "px";
    this._div.style.top = pixel.y - 4 + "px";
};
